package com.aier.common.action;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.common.common.CommonSession;
import com.aier.common.dao.ICommonDAO;
import com.aier.common.service.IFeedbackService;
import com.aier.proxy.service.IProxyService;
import com.aier.user.common.UserFinalPageSize;
import com.aier.user.entity.Feedback;
import com.aier.user.entity.FeedbackContent;

@Scope("prototype")
@Component("commonFeedbackAction")
public class CommonFeedbackAction extends CommonBaseAction {
    /**
     * 消息反馈
     */
    private static final long serialVersionUID = 1L;
    
    @Resource(name = "feedbackService")
    private IFeedbackService feedbackService;
    
    //页数
    private int page;
    // 每页显示记录数
    private int page_size;
    // 总页数
    private int page_count;
    // 总数
    private int count;
    //错误码
    private int s;
    
    // 学校编号
    private int sid;
    
    // 排序方式
    private String sord;
    // 排序字段
    private String sort;
    
    // 意见列表
    private List<Feedback> fbList;
    
    // 意见id
    private Long fbid;
    
    // 评分
    private Short score;
    
    // 标题
    private String title;
    
    // 内容
    private String content;
    
    // 意见的状态
    private Short state;
    
    private List<FeedbackContent> contentList;
    
    private Long uid;
    
    private String realname;
    
    private Feedback feedback;
    
    @Override
    public String execute() {
        realname = feedbackService.searchRealname((Long)session.get(CommonSession.SESSION_ACCOUNT_ID));
        if (null != fbid && fbid != 0) {
            feedback = feedbackService.searchFeedbackByFbid(fbid);
        }
        return SUCCESS;
    }
    
    @SuppressWarnings("unchecked")
    public String searchFeedback() {
        if (page <= 0) {
            page = 1;
        }
        int sortable=-1;
        if("cdate".equals(sort)){
            sortable = ("asc".equals(sord))?IProxyService.ENTRANCE_SORTABLE_SN:IProxyService.ENTRANCE_SORTABLE_SN_DESC;
        }
        Map<String, Object> map = null;
        map = feedbackService.searchFeedbackByUid(page,UserFinalPageSize.USERIC_ICARD_PAGESIZE,
                (Long)session.get(CommonSession.SESSION_ACCOUNT_ID),sortable);
        fbList = (List<Feedback>) map.get(ICommonDAO.OBJ_LIST);
        if (null == fbList) {
            s = 0;
            return SUCCESS;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        s = 1;
        return SUCCESS;
    }

    // 评分
    public String commitScore() {
        s = feedbackService.updateFeedbackByid(score, fbid);
        return SUCCESS;
    }
    
    // 发表意见
    public String commitAdvice() {
        Timestamp cdate = new Timestamp(new Date().getTime());
        s = feedbackService.insertFeedback((Long)session.get(CommonSession.SESSION_ACCOUNT_ID), title, cdate,content);
        return SUCCESS;
    }
    
    // 回复
    public String commitFeedback() {
        Timestamp cdate = new Timestamp(new Date().getTime());
        s = feedbackService.insertFeedbackContent(fbid, content, cdate, (Long)session.get(CommonSession.SESSION_ACCOUNT_ID),state,null);
        return SUCCESS;
    }
    
    // 查询意见反馈列表
    public String queryFeedbackContent() {
        contentList = feedbackService.searchContent(fbid);
        return SUCCESS;
    }

    public int getPage() {
        return page;
    }


    public void setPage(int page) {
        this.page = page;
    }


    public int getPage_size() {
        return page_size;
    }


    public int getPage_count() {
        return page_count;
    }


    public int getCount() {
        return count;
    }


    public int getS() {
        return s;
    }

    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public void setFeedbackService(IFeedbackService feedbackService) {
        this.feedbackService = feedbackService;
    }

    public List<Feedback> getFbList() {
        return fbList;
    }

    public void setFbList(List<Feedback> fbList) {
        this.fbList = fbList;
    }
    
    public void setSord(String sord) {
        this.sord = sord;
    }

    public void setSort(String sort) {
        this.sort = sort;
    }

    public Long getFbid() {
        return fbid;
    }

    public void setFbid(Long fbid) {
        this.fbid = fbid;
    }

    public Short getScore() {
        return score;
    }

    public void setScore(Short score) {
        this.score = score;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Short getState() {
        return state;
    }

    public void setState(Short state) {
        this.state = state;
    }

    public List<FeedbackContent> getContentList() {
        return contentList;
    }

    public void setContentList(List<FeedbackContent> contentList) {
        this.contentList = contentList;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public Feedback getFeedback() {
        return feedback;
    }

    public void setFeedback(Feedback feedback) {
        this.feedback = feedback;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }
    
}
